//
//  MyFlutterViewFactory.m
//  Runner
//
//  Created by mac on 2021/6/1.
//

#import "MyFlutterViewFactory.h"
#import "MyFlutterView.h"

@implementation MyFlutterViewFactory
-(instancetype) initWithFlutterBinaryMessenger:(NSObject<FlutterBinaryMessenger> *)messenger{
    self = [super init];
    self.messenger = messenger;
    FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"com.flutter.guide.MyFlutterView" binaryMessenger:messenger];
    [channel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult  _Nonnull result) {
        if ([call.method isEqualToString:@"callNative"]) {
            NSDictionary *dic = call.arguments;
            NSString *action = dic[@"action"];
            //flutter传递给OC的数据
            NSDictionary *dataDic = dic[@"data"];
            NSLog(@"%@",dataDic);
            if ([action isEqualToString:@"closeFlutter"]) {
            }
            result(@{@"msg":@"原生返回Flutter"});
        } else {
            result(@{});
        }
    }];
    
    return self;
}
- (NSObject<FlutterMessageCodec> *)createArgsCodec{
    return [FlutterStandardMessageCodec sharedInstance];
}
- (NSObject<FlutterPlatformView> *)createWithFrame:(CGRect)frame viewIdentifier:(int64_t)viewId arguments:(id)args{
    return [[MyFlutterView alloc] initWithFrame:frame viewID:viewId args:args messenger:self.messenger];
}
@end
